package com.fr.util;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Finder
{
  public static Class[] findClassesUnderDir(File paramFile)
  {
    return findClassesMatchedUnderDir(paramFile, Object.class);
  }

  public static Class[] findClassesMatchedUnderDir(File paramFile, Class paramClass)
  {
    return findClassesMatchedUnderDir(paramFile, "", paramClass);
  }

  public static Class[] findClassesMatchedUnderDir(File paramFile, String paramString, Class paramClass)
  {
    File[] arrayOfFile = findJavaFilesUnderDirectory(paramFile);
    ArrayList localArrayList = new ArrayList();
    String str1 = paramFile.getAbsolutePath();
    int i = str1.length();
    if ((!(str1.endsWith("\\"))) && (!(str1.endsWith("/"))))
      ++i;
    for (int j = 0; j < arrayOfFile.length; ++j)
    {
      String str2 = arrayOfFile[j].getAbsolutePath();
      String str3 = str2.substring(i, str2.length() - ".java".length());
      String str4 = str3.replaceAll("[\\/\\\\]", ".");
      try
      {
        Class localClass = Class.forName(paramString + str4);
        if (Utils.classInstanceOf(localClass, paramClass))
          localArrayList.add(localClass);
      }
      catch (ClassNotFoundException localClassNotFoundException)
      {
        localClassNotFoundException.printStackTrace();
      }
    }
    return ((Class[])localArrayList.toArray(new Class[localArrayList.size()]));
  }

  protected static File[] findJavaFilesUnderDirectory(File paramFile)
  {
    return findFilesUnderDirectory(paramFile, "java");
  }

  public static File[] findFilesUnderDirectory(File paramFile, String paramString)
  {
    if (paramFile.isDirectory())
    {
      ArrayList localArrayList = new ArrayList();
      File[] arrayOfFile = paramFile.listFiles();
      for (int i = 0; i < arrayOfFile.length; ++i)
        localArrayList.addAll(Arrays.asList(findFilesUnderDirectory(arrayOfFile[i], paramString)));
      return ((File[])localArrayList.toArray(new File[localArrayList.size()]));
    }
    if (isSuffixMatched(paramFile, paramString))
      return new File[] { paramFile };
    return new File[0];
  }

  protected static boolean isSuffixMatched(File paramFile, String paramString)
  {
    return ((paramFile.isFile()) && (paramFile.getName().toUpperCase().endsWith("." + paramString.toUpperCase())));
  }
}